﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YunSpace.Application.SiteMgr;
using YunSpace.Core;
using YunSpace.Domain.ViewModel.SiteMgr;

namespace YunSpace.Web.Areas.ClientManager.Controllers
{
    public class DemandInfosController : ControllerBase
    {
        // GET: ClientManager/DemandInfos
        DemandInfoApp app = new DemandInfoApp();       
        public ActionResult MyDemandManager() {
            return View();
        }

        public ActionResult Share() {
            return View();
        }

        public ActionResult Infos() {
            return View();
        }

        [HttpGet]
        public ActionResult GetItems() {
            var data = new
            {
                F_ActivityType = app.GetItemList("ActivityType"),
                First_ActivityType = app.GetItemList("FirstActivityType"),
                F_ActivityCityId = app.GetAllCitys(),
                SiteClients = app.GetClients(),
                F_SiteType = app.GetItemList("SiteType"),
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetItemListJson()
        {
            //var citys = app.GetCitys();
            var data = new
            {
                F_ClientType = app.GetItemList("khlx"),
                F_CompanyType = app.GetItemList("gslx"),
                F_ClientLevel = app.GetItemList("khdj"),
                F_IndustryId = app.GetItemList("sshy"),
                F_DepartmentId = app.GetItemList("bmmc"),
                F_PositionId = app.GetItemList("gszw"),
                F_ActivityType = app.GetItemList("ActivityType"),
                First_ActivityType = app.GetItemList("FirstActivityType"),
                F_SiteType = app.GetItemList("SiteType"),
                F_CityId = app.GetAllCitys(),
                F_AreaId = app.GetAllAreas(),
                SiteClients = app.GetClients(),
                Brands = app.GetBrands(),
                Contacts = app.GetClientsContacts(),
                Projects = app.GetClientsAllProjects()
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetAllCitys()
        {
            var result = app.GetAllCitys();
            return Content(result.ToJson());
        }

        [HttpGet]
        public ActionResult GetGridData(Pagination pagination, string queryJson)
        {
            var data = new
            {
                rows = app.GetDemandList(pagination, queryJson),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetGridDataByUserId(Pagination pagination, string queryJson)
        {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();
            var data = new
            {
                rows = app.GetGridDataByUserId(pagination, queryJson, LoginInfo.UserId),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetClientOrderHistoryList(Pagination pagination, string F_ClientId,string F_Id)
        {
            var data = new
            {
                rows = app.GetClientOrderHistoryList(pagination, F_ClientId, F_Id),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetDemandAllotList(Pagination pagination) {
            var data = new
            {
                rows = app.GetDemandAllotList(pagination),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetMemandEntity(string F_Id) {
            var data = app.GetMemandEntity(F_Id);
            return Content(data.ToJson());
        }

        /// 提交表单
        /// </summary>
        /// <param name="siteEntity">表单实体</param>
        [HttpPost]
        [HandlerAjaxOnly]        
        public ActionResult SubmitForm(ClientTelDemandActionModel entity)
        {
            var result= app.SubmitForm(entity);
            return Content(result.ToJson());
        }

        /// 提交表单
        /// </summary>
        /// <param name="siteEntity">表单实体</param>
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitAllotForm(string F_Id,string F_UserId)
        {
            app.SubmitAllotForm(F_Id, F_UserId);
            return Success("操作成功。");
        }
    }
}